//
//  OACountyTableViewController.m
//  OASystem
//
//  Created by zhoupengfei on 15/12/6.
//  Copyright © 2015年 zpf. All rights reserved.
//

#import "OACountyTableViewController.h"
#import "HttpTools.h"
#import "CountyListModel.h"
#import "MBProgressHUD.h"
#import "OAExpendViewController.h"
@interface OACountyTableViewController ()

@end

@implementation OACountyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"选择人员";
    [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray * array = @[@{@"userId":userId}];
    [HttpTools requestWithURL:KExchTree arrays:array method:KGlobalTree success:^(id JSON) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
        NSArray * data = JSON[@"data"];
        if (data.count) {
            NSDictionary * ditc = [data firstObject];
            [self.contentsArray addObjectsFromArray:[CountyListModel dataWithArray:ditc[@"Parent"]]];
            [self.tableView reloadData];
        }
        
    } failure:^(NSError *error) {
        
         [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
    }];

}



#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.contentsArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellId" forIndexPath:indexPath];
    CountyListModel * listModel = self.contentsArray[indexPath.row];
    cell.textLabel.text = listModel.bmmc;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     CountyListModel * listModel = self.contentsArray[indexPath.row];
    OAExpendViewController * expendVC = [[OAExpendViewController alloc] init];
    expendVC.identifierString = listModel.path;
    [self.navigationController pushViewController:expendVC animated:YES];
}




@end
